package com.hqbzl.c1;

public class TestSearch {
    public static int search(int[] arr, int target) {
        int i = 0;
        int j = arr.length - 1;
        while (i <= j) {
            //int m = (i + j) / 2;
            int m = (i + j) >>> 1;
            int am = arr[m];
            if (target < am) {
                j = m - 1;
            } else if (target > am) {
                i = m + 1;
            } else {
                return m;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{2, 3, 4, 5, 6, 7, 8};
        final int search = search(arr, 7);
        System.out.println("search = " + search);
    }
}
